﻿using System;
using System.Collections.Generic;
using OpenTK.Input;

namespace Chimp.Core
{
    public class ChimpI
    {
        private static MouseDevice Mouse;
        private static readonly Dictionary<MouseButton, bool> Buttons = new Dictionary<MouseButton, bool>();
        private static readonly Dictionary<Key, bool> Keys = new Dictionary<Key, bool>();

        /// <summary>
        /// Internal function.
        /// </summary>
        private static bool initdone;

        public static void Init()
        {
  
  
          //  Mouse = ChimpApp.Cur.Mouse;
           // Mouse.ButtonDown += ButtonDown;
           // Mouse.ButtonUp += Mouse_ButtonUp;

            //ChimpApp.Cur.Keyboard.KeyDown += Keyboard_KeyDown; // new KeyDownEvent(Keyboard_KeyDown);
            //ChimpApp.Cur.Keyboard.KeyUp += Keyboard_KeyUp; // new KeyUpEvent(Keyboard_KeyUp);
        }

        private static void Keyboard_KeyUp(object obj, KeyboardKeyEventArgs e)
        {
            if (Keys.ContainsKey(e.Key))
            {
                Keys.Remove(e.Key);
            }
            Keys.Add(e.Key, false);
        }

        private static void Keyboard_KeyDown(object obj, KeyboardKeyEventArgs e)
        {
            if (Keys.ContainsKey(e.Key))
            {
                Keys.Remove(e.Key);
            }
            Keys.Add(e.Key, true);
        }


        private static void Mouse_ButtonUp(object sender, MouseButtonEventArgs e)
        {
            Buttons.Remove(e.Button);
            Buttons.Add(e.Button, false);
    
        }

        public static void ButtonDown(object obj, MouseButtonEventArgs evt)
        {
            if (Buttons.ContainsKey(evt.Button))
            {
                Buttons.Remove(evt.Button);
            }
            Buttons.Add(evt.Button, true);
           
        }

        public static void ButtonUp(object obj, MouseButtonEventArgs evt)
        {
        }

        public static bool IsMouseDown(MouseButton button)
        {
            if (Buttons.ContainsKey(button))
            {
                return Buttons[button];
            }
            return false;
        }

        public static bool IsKeyDown(Key key)
        {
            if (!Keys.ContainsKey(key))
            {
                return false;
            }
            return Keys[key];
        }

        public static float mMX=0, mMY=0;
        public static float MouseX()
        {
            return mMX;
        }

        public static float MouseY ( )
        {
            return mMY;
        }

        public static float MouseXI()
        {
            return mXI;
        }

        public static float MouseYI()
        {
            return mYI;
        }

        public static float mXI = 0, mYI = 0;
    }

}